package com.jsle.financial.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jsle.common.dao.mybatis.BaseDao;
import com.jsle.financial.domain.DocPublish;
import com.jsle.financial.util.Constants;
import com.jsle.financial.vo.Result;

public class FileDaoImpl extends BaseDao  implements FileDao{
	private Log log = LogFactory.getLog(FileDaoImpl.class);
	
	public Result saveDoc(DocPublish doc) {
		Result result = new Result();
		try {
			boolean docResult = insert("DocPublish.insert",doc);
			if(docResult){
				result.setResultCode(Constants.FC_RESULT_SUCCESS_CODE);
				result.setResultMessage(Constants.FC_RESULT_SUCCESS_MESSAGE);
			}else{
				result.setResultCode(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_CODE);
				result.setResultMessage(String.format(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_MESSAGE, "User"));
			}
		} catch (Exception e) {
			result.setResultCode(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_MESSAGE, "User"));
			log.error("saveDoc error## "+ e.getMessage());
		}
		return result;
	}

	public Result findDocs(DocPublish doc) {
		Result result = new Result();
		try {
			List<DocPublish> docs = queryForList("DocPublish.selDocs", doc);
			if(docs!=null){
				result.setResultCode(Constants.FC_RESULT_SUCCESS_CODE);
				result.setResultMessage(Constants.FC_RESULT_SUCCESS_MESSAGE);
				result.setResultValue(docs);
			}else{
				result.setResultCode(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_CODE);
				result.setResultMessage(String.format(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_MESSAGE, "User"));
			}
		} catch (Exception e) {
			result.setResultCode(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Dao.FC_RESULT_INSERT_DAO_ERROR_MESSAGE, "User"));
			log.error("findDocs error## "+ e.getMessage());
		}
		return result;
	}

}
